package ru.ntcreb.csir.libs.methods.SVCH.xml.handler;

import java.util.Map;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class TractParserHandler extends DefaultHandler {

	private Map<Double, Double> result;

	public TractParserHandler(Map<Double, Double> result) {
		this.result = result;
	}

	private boolean inputVoltageFlag = false;
	private boolean outputCurrencyFlag = false;

	private double tempInputVoltage;
	private double tempOutputCurrency;

	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		if (qName.equalsIgnoreCase("inputVoltage")) {
			inputVoltageFlag = true;
		}

		if (qName.equalsIgnoreCase("outputCurrency")) {
			outputCurrencyFlag = true;
		}
	}

	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		if (qName.equalsIgnoreCase("entry")) {
			result.put(tempInputVoltage, tempOutputCurrency);
		}

	}

	public void characters(char ch[], int start, int length)
			throws SAXException {

		if (inputVoltageFlag) {
			tempInputVoltage = new Double(new String(ch, start, length));
			inputVoltageFlag = false;

		}

		if (outputCurrencyFlag) {

			tempOutputCurrency = new Double(new String(ch, start, length));
			outputCurrencyFlag = false;
		}

	}

}
